<template>
	<view class="container">
		<u-toast ref="uToast" />
		<u-navbar :is-back="true" title="添加课程" back-icon-color='#333333' height="40" :border-bottom="false">
		</u-navbar>
		<u-select v-model="show" mode="mutil-column-auto" :list="grade_list" @confirm="commit"></u-select>
		<view class="list">
			<view class="declarant">
				<text>申报人</text>
				<text>{{full_name}}</text>
			</view>
			<view class="technical">
				<text>在校职称</text>
				<u-input v-model="form.school_position" style="margin-left:200rpx; width: 200rpx;" :type="type"
					placeholder="单行输入" :border="border" input-align="right" />
			</view>
			<view class="course_name">
				<text>课程名称</text>
				<u-input v-model="form.name" style="margin-left:200rpx; width: 200rpx;" :type="type" placeholder="单行输入"
					:border="border" input-align="right" />
			</view>
			<view class="abstract">
				<text>内容简介</text>
				<u-input v-model="form.introduction" style="margin-left:200rpx; width: 200rpx;" :type="type"
					placeholder="单行输入" :border="border" input-align="right" />
			</view>
			<view class="alternative">
				<text>选择对象</text>
				<text>{{grade_name}}</text>
				<text @click="show=true"></text>
			</view>
			<view class="require_reason">
				<text>学生要求说明</text>
			</view>
			<view class=""
				style="width:94%; height:15rpx; margin-left:3%; background:#F2F2F2; border-top-left-radius:12rpx; border-top-right-radius:12rpx;">

			</view>
			<textarea value="" v-model="form.remark" placeholder="单行输入"
				style="width:94%; height:180rpx; margin-left:3%; background:#F2F2F2; text-indent:1em; border-bottom-left-radius:12rpx; border-bottom-right-radius:12rpx;" />
			<view class="" style="width:100%; height:84rpx;">
			</view>
		</view>
		<view class="confirm">
			<view class="verify" @click="addCourse">
				{{verify}}
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../request.js'
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				input_content: '',
				technical_content: '',
				course_content: '',
				abstract_content: '',
				verify: '提交申报',
				content: '',
				border: false,
				type: 'text',
				grade_list: [],
				show: false,
				grade_name: '',
				grade_arr: [],
				form: {
					name: '',
					school_position: '',
					introduction: '',
					link_grade_ids: '',
					remark: '',
				}
			}
		},
		onLoad() {
			this.gradeLists();
			this.$store.dispatch('getTodos');
		},
		computed: {
			...mapState(['full_name']),
		},
		methods: {
			commit(e) {
				this.grade_name = e[0].label;
				this.grade_arr.push(e[0].value);
				this.form.link_grade_ids = this.grade_arr.join(',');
			},
			gradeLists() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'teacher/classes/gradeLists',
					method: 'post',
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data);
							res.data.data.forEach((item, index) => {
								_this.grade_list.push({
									label: item.name,
									value: item.grade_id,
								})
							})
							console.log(_this.grade_list);
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			addCourse() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'teacher/electiveCourse/add',
					method: 'post',
					data: {
						...this.form,
					},
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data);
							_this.$toLink('../declare_course/declare_course', {}, 2);
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		overflow: hidden;
		height: 100vh;
		background: #F2F2F2;

		.list {
			width: 710rpx;
			margin-left: 20rpx;
			margin-top: 20rpx;
			background: #fff;
			border-radius: 12rpx;
			overflow: hidden;

			.declarant {
				width: 94%;
				margin-left: 3%;
				height: 84rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				border-bottom: 1px solid #F2F2F2;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 150rpx;
					}

					&:nth-child(2) {
						width: 500rpx;
						text-align: right;
						color: #333333;
					}
				}
			}

			.technical {
				width: 94%;
				margin-left: 3%;
				height: 84rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				border-bottom: 1px solid #F2F2F2;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 150rpx;
					}
				}
			}

			.course_name {
				width: 94%;
				margin-left: 3%;
				height: 84rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				border-bottom: 1px solid #F2F2F2;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 150rpx;
					}
				}
			}

			.abstract {
				width: 94%;
				margin-left: 3%;
				height: 84rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				border-bottom: 1px solid #F2F2F2;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 150rpx;
					}
				}
			}

			.alternative {
				width: 94%;
				display: flex;
				margin-left: 3%;
				align-items: center;
				justify-content: flex-start;
				height: 84rpx;
				border-bottom: 1px solid #F2F2F2;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 200rpx;
					}

					&:nth-child(2) {
						color: #333333;
						text-align: right;
						width: 370rpx;
					}

					&:nth-child(3) {
						width: 0rpx;
						margin-top: 20rpx;
						margin-left: 40rpx;
						height: 0rpx;
						border-width: 18rpx 18rpx 18rpx 18rpx;
						border-color: #ccc transparent transparent transparent;
						border-style: solid;
					}
				}
			}

			.require_reason {
				width: 94%;
				display: flex;
				margin-left: 3%;
				align-items: center;
				justify-content: flex-start;
				height: 84rpx;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 200rpx;
					}
				}
			}

		}

		.confirm {
			width: 100%;
			height: 250rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.verify {
				width: 200rpx;
				height: 60rpx;
				border-radius: 50rpx;
				text-align: center;
				line-height: 60rpx;
				background: linear-gradient(to right, #2C78FE, #32B0FF);
				color: #fff;
				font-size: 30rpx;
			}
		}
	}
</style>
